package com.mit.service.maintenance.dao.impl;

import java.util.List;

import com.mit.common.exception.NoRecordUpdateException;
import com.mit.common.maintenance.dto.ProductTypeDTO;
import com.mit.service.core.dao.AbstractDAO;
import com.mit.service.maintenance.dao.IProductTypeDAO;

public class ProductTypeDAOImpl extends AbstractDAO implements IProductTypeDAO {

	@Override
	public ProductTypeDTO createProductType(ProductTypeDTO productTypeDTO) {
		
		Integer id = (Integer)  getSqlMapClientTemplate().insert("insertProductType", productTypeDTO);
		productTypeDTO.setId(id);
		return productTypeDTO;
	}

	@Override
	public ProductTypeDTO updateProductType(ProductTypeDTO productTypeDTO)
			throws NoRecordUpdateException {
		int rs = getSqlMapClientTemplate().update("updateProductType", productTypeDTO);
		if(rs == 0)
			throw new NoRecordUpdateException();
		return productTypeDTO;
	}

	@Override
	public List<ProductTypeDTO> retrieveProductTypes(int organizationId) {
		
		return getSqlMapClientTemplate().queryForList("selectProductTypes", organizationId);
	}

}
